/*
 * @FilePath: /three/src/router/index.ts
 * 介绍:路由文件
 */

import {
  createRouter,
  // createWebHistory,
  createWebHashHistory,
  RouteRecordRaw,
} from "vue-router"; //引入路由
const modules = import.meta.glob("./module/**.ts", { eager: true });

const routes: Array<RouteRecordRaw> = [];
Object.values(modules).forEach((val: any) => {
  const module: Array<RouteRecordRaw> = val.default;
  routes.push(...module);
});

const router = createRouter({
  history: createWebHashHistory(),
  routes,
});

//解析守卫
// router.beforeResolve(async (to) => {
//   return true;
// });

//前置路由守卫
router.beforeEach(async (to, from, next) => {
  const whiteList = ["home"];
  if (whiteList.includes(to.name as string)) return next();
  next({ name: "home" });
});

export default router;
